package com.insigma.business.qrcode.intell.util;


import com.github.houbb.segment.api.ISegmentResult;
import com.github.houbb.segment.util.SegmentHelper;
import com.google.common.collect.Sets;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.logging.log4j.util.Strings;

import java.util.List;
import java.util.Set;


public class WordSegmentUtils {

    public static Set<String> segmentWord(String str) {
        List<ISegmentResult> resultList = SegmentHelper.segment(str);

        Set<String> result = Sets.newHashSet();
        if (CollectionUtils.isNotEmpty(resultList)) {
            for (ISegmentResult segment : resultList) {
                String word = segment.word();
                if (Strings.isNotBlank(word)) {
                    String afterReplace = word.replaceAll( "[\\pP+~$`^=|<>～｀＄＾＋＝｜＜＞￥×]" , "");
                    if (Strings.isNotBlank(afterReplace)) {
                        result.add(afterReplace);
                    }
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Set<String> strings = segmentWord("下城区服务电话");
        System.out.println();
    }
}
